<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Insert title here</title>
  <style type="text/css">
    select {
      width: 100px;
      height: 140px;
    }

    div {
      width: 130px;
      float: left;
      text-align: center;
    }
  </style>
  <script type="text/javascript" src="script/jquery-1.7.2.js"></script>
  <script type="text/javascript">
    $(function () {
      const delA = function () {
        const items = $("select[name=sel01] option:selected");
        items.remove();
        items.each(
          function () {
            this.selected = !this.selected
          }
        )
        items.appendTo($("select[name=sel02]"))
      }


      $("button:eq(0),select[name=sel01] option").dblclick(
        delA
      )


      $("button:eq(1)").click(
        function () {
          const items = $("select[name=sel01] option");
          items.remove();
          items.appendTo($("select[name=sel02]"))
        }
      )

      $("select[name=sel01]").on("dblclick",delA)
      //解决使用jQuery采用append添加的元素事件无效的方法
      //$("父节点").on("mouseout","你要点击的节点",function(){});
      // 想想也就理解设计师的做法了，不断的从父节点遍历下面的选中子节点，这种方法确实是一种思路

      const delB = function () {
        const items = $("select[name=sel02] option:selected")
        items.remove()
        items.each(
          function () {
            this.selected = !this.selected
          }
        )
        items.appendTo($("select[name=sel01]"))
      }

      $("select[name=sel02] ,button:eq(2)").dblclick(
        delB
      )

      $("select[name=sel02] option").on("dblclick", delB)

      $("button:eq(3)").click(
        function () {
          const items = $("select[name=sel02] option")
          items.remove();
          items.appendTo($("select[name=sel01]"))
        }
      )
    })


  </script>
</head>
<body>

<div id="left">
  <select multiple="multiple" name="sel01">
    <option value="opt01">选项1</option>
    <option value="opt02">选项2</option>
    <option value="opt03">选项3</option>
    <option value="opt04">选项4</option>
    <option value="opt05">选项5</option>
    <option value="opt06">选项6</option>
    <option value="opt07">选项7</option>
    <option value="opt08">选项8</option>
  </select>

  <button>选中添加到右边</button>
  <button>全部添加到右边</button>
</div>
<div id="rigth">
  <select multiple="multiple" name="sel02">
  </select>
  <button>选中删除到左边</button>
  <button>全部删除到左边</button>
</div>

</body>
</html>
